package com.evenmo.hrms.mapper.oldmapper.dynaSqlProvider;

import com.evenmo.hrms.pojo.Employee;
import org.apache.ibatis.jdbc.SQL;

public class EmployeeDynaSqlProvider {
    public String updateByParams(Employee employee) {

        return new SQL() {
            {

                UPDATE("employee");

                // 部门ID
                if (employee.getDeptId() != null) {
                    SET("deptId=#{deptId}");
                }

                // 职位ID
                if (employee.getJobId() != null) {
                    SET("jobId=#{jobId}");
                }
                // 员工姓名
                if (employee.getName() != null) {
                    SET("name=#{name}");

                }
                // 身份证号码

                if (employee.getCardId() != null) {
                    SET("cardId=#{cardId}");
                }
                // 员工住址
                if (employee.getAddress() != null) {
                    SET("address=#{address}");
                }
                // 邮政编码
                if (employee.getPostCode() != null) {
                    SET("postCode=#{postCode}");
                }
                // 固定电话
                if (employee.getTel() != null) {
                    SET("tel=#{tel}");
                }
                // 手机号码
                if (employee.getPhone() != null) {
                    SET("phone=#{phone}");
                }
                // qq号码
                if (employee.getQqNumber() != null) {
                    SET("qqNumber=#{qqNumber}");
                }
                // email邮箱
                if (employee.getEmail() != null) {
                    SET("email=#{email}");
                }
                // 性别,1为男，2为女
                if (employee.getSex() != null) {
                    SET("sex=#{sex}");
                }
                // 政治团体类型
                if (employee.getParty() != null) {
                    SET("party=#{party}");

                }
                // 生日
                if (employee.getBirthday() != null) {
                    SET("birthday=#{birthday}");
                }
                // 民族
                if (employee.getRace() != null) {
                    SET("race=#{race}");
                }
                // 受教育程度
                if (employee.getEducation() != null) {
                    SET("education=#{education}");
                }
                // 特长
                if (employee.getSpeciality() != null) {
                    SET("speciality=#{speciality}");
                }
                // 爱好
                if (employee.getHobby() != null) {
                    SET("hobby=#{hobby}");
                }
                // 备注
                if (employee.getRemark() != null) {
                    SET("remark=#{remark}");
                }
                // 创建时间

                if (employee.getCreateTime() != null) {
                    SET("createTime=#{createTime}");
                }
                WHERE("id=#{id}");
            }
        }.toString();
    }

    public String insertByParams(Employee employee) {
        return new SQL() {
            {

                INSERT_INTO("employee");

                // 部门ID
                if (employee.getDeptId() != null) {
                    VALUES("deptId", "#{deptId}");
                }

                // 职位ID
                if (employee.getJobId() != null) {
                    VALUES("jobId", "#{jobId}");
                }
                // 员工姓名
                if (employee.getName() != null) {
                    VALUES("name", "#{name}");

                }
                // 身份证号码

                if (employee.getCardId() != null) {
                    VALUES("cardId", "#{cardId}");
                }
                // 员工住址
                if (employee.getAddress() != null) {
                    VALUES("address", "#{address}");
                }
                // 邮政编码
                if (employee.getPostCode() != null) {
                    VALUES("postCode", "#{postCode}");
                }
                // 固定电话
                if (employee.getTel() != null) {
                    VALUES("tel", "#{tel}");
                }
                // 手机号码
                if (employee.getPhone() != null) {
                    VALUES("phone", "#{phone}");
                }
                // qq号码
                if (employee.getQqNumber() != null) {
                    VALUES("qqNumber", "#{qqNumber}");
                }
                // email邮箱
                if (employee.getEmail() != null) {
                    VALUES("email", "#{email}");
                }
                // 性别,1为男，2为女
                if (employee.getSex() != null) {
                    VALUES("sex", "#{sex}");
                }
                // 政治团体类型
                if (employee.getParty() != null) {
                    VALUES("party", "#{party}");

                }
                // 生日
                if (employee.getBirthday() != null) {
                    VALUES("birthday", "#{birthday}");
                }
                // 民族
                if (employee.getRace() != null) {
                    VALUES("race", "#{race}");
                }
                // 受教育程度
                if (employee.getEducation() != null) {
                    VALUES("education", "#{education}");
                }
                // 特长
                if (employee.getSpeciality() != null) {
                    VALUES("speciality", "#{speciality}");
                }
                // 爱好
                if (employee.getHobby() != null) {
                    VALUES("hobby", "#{hobby}");
                }
                // 备注
                if (employee.getRemark() != null) {
                    VALUES("remark", "#{remark}");
                }
                // 创建时间

                if (employee.getCreateTime() != null) {
                    VALUES("createTime", "#{createTime}");
                }
                WHERE("id=#{id}");
            }
        }.toString();
    }

    public String selectByparams(Employee employee) {
        return new SQL() {
            {
                SELECT("*");
                FROM("employee");
                if (employee.getJobId() != null) {
                    WHERE("jobId=#{jobId}");
                }
                if (employee.getDeptId() != null) {
                    WHERE("deptId=#{deptId}");
                }
                if (employee.getRemark() != null) {
                    WHERE("remark like concat('%',#{remark},'%')");
                }
                if (employee.getHobby() != null) {
                    WHERE("hobby like concat('%',#{hobby},'%')");
                }
                if (employee.getSpeciality() != null) {
                    WHERE("speciality like concat('%',#{speciality},'%')");
                }
                if (employee.getEducation() != null) {
                    WHERE("education=#{education}");
                }
                if (employee.getParty() != null) {
                    WHERE("party like concat('%',#{party},'%')");
                }
                if (employee.getCreateTime() != null) {
                    WHERE("createTime=#{createTime}");
                }
                if (employee.getRace() != null) {
                    WHERE("race=#{race}");
                }
                if (employee.getSex() != null) {
                    WHERE("sex=#{sex}");
                }
                if (employee.getEmail() != null) {
                    WHERE("email like concat('%',#{email},'%')");
                }
                if (employee.getQqNumber() != null) {
                    WHERE("qqNumber=#{qqNumber}");
                }
                if (employee.getPhone() != null) {
                    WHERE("phone like concat('%',#{phone},'%')");
                }
                if (employee.getTel() != null) {
                    WHERE("tel like concat('%',#{tel},'%')");
                }
                if (employee.getPostCode() != null) {
                    WHERE("postCode like concat('%',#{postCode},'%')");
                }
                if (employee.getAddress() != null) {
                    WHERE("address like concat('%',#{address},'%')");
                }
                if (employee.getCardId() != null) {
                    WHERE("cardId=#{cardId}");
                }
                if (employee.getName() != null) {
                    WHERE("name like concat('%',#{name},'%')");
                }
                if (employee.getBirthday() != null) {
                    WHERE("birthday=#{birthday}");
                }

            }
        }.toString();
    }


    public String countByParams(Employee employee) {
        return new SQL() {

            {

                SELECT("count(1)");
                FROM("employee");
                if (employee.getAddress() != null) {
                    WHERE("address like concat('%',#{address},'%')");
                }
                if (employee.getName() != null) {
                    WHERE("name like concat('%',#{name},'%')");
                }
                if (employee.getSex() != null) {
                    WHERE("sex=#{sex}");
                }
                if (employee.getParty() != null) {
                    WHERE("party like concat('%',#{party},'%')");
                }
                if (employee.getRace() != null) {
                    WHERE("race like concat('',#{race},'%')");
                }
                if (employee.getEducation() != null) {
                    WHERE("education like concat('%',#{education},'%')");
                }
                if (employee.getDeptId() != null) {
                    WHERE("deptId=#{deptId}");
                }
                if (employee.getJobId() != null) {
                    WHERE("jobId=#jobId}");
                }

            }
        }.toString();
    }
}
